package
{
	import flash.display.Sprite;
	
	import mapper.xml.XmlMapper;
	
	public class TestMapper extends Sprite
	{
		public var xmlMapper:XmlMapper;
		public function TestMapper()
		{
			test1();
			test2();
			test3();
		}
		
		private function test1():void
		{
			var testXML:XML = XML 
				(
					<test>
						<hello>worlds</hello>
					</test>
				);
			xmlMapper = new XmlMapper();
			// 把TestVO类型注册到mapper里面，给它一个别名test与xml的根节点对应
			xmlMapper.regClz(TestVO,"test");
			var obj:TestVO = xmlMapper.fromXML(testXML);
			var xmlStr:* = xmlMapper.toXML(obj);
			trace(xmlStr);
		}
		
		/**
		 * 复杂的例子
		 */
		private function test2():void
		{
			var testXML:XML = XML 
				(
					<test2>
						<helloTest>
							<hello>worlds</hello>
						</helloTest>
						<helloObj>
							<attr1>1</attr1>
							<attr2>2</attr2>
						</helloObj>
						<helloLs>
							<String>worlds</String>
							<int>11</int>
							<test>
								<hello>worlds2</hello>
							</test>
							<test>
								<hello>worlds3</hello>
							</test>
						</helloLs>
					</test2>
				);
			xmlMapper = new XmlMapper();
			// 把TestVO类型注册到mapper里面，给它一个别名test与xml的根节点对应
			xmlMapper.regClz(TestVO,"test");
			xmlMapper.regClz(Test2VO,"test2");
			var obj:Test2VO = xmlMapper.fromXML(testXML);
			var xmlStr:* = xmlMapper.toXML(obj);
			trace(xmlStr);
		}
		
		/**
		 * 引用属性xml
		 */
		private function test3():void
		{
			var testXML:XML = XML 
				(
					<test3>
					  <test2>
						<hello>
						  words
						</hello>
					  </test2>
					  <test1 reference="../test2"/>
					</test3>
				);
			xmlMapper = new XmlMapper();
			// 把TestVO类型注册到mapper里面，给它一个别名test与xml的根节点对应
			xmlMapper.regClz(TestVO,"test");
			xmlMapper.regClz(Test3VO,"test3");
			var obj:Test3VO = xmlMapper.fromXML(testXML);
			var xmlStr:* = xmlMapper.toXML(obj);
			trace(xmlStr);
		}
	}
}